<template>
  <div class="containner">
    <!-- 面包屑导航 -->
    <el-card>
      <el-breadcrumb separator=">">
        <el-breadcrumb-item :to="{ path: '/' }">薪酬管理</el-breadcrumb-item>
        <el-breadcrumb-item>
          <a href="/">设置薪酬规则</a>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </el-card>
    <!-- 选项卡部分 -->
    <el-tabs type="border-card" style="height:600px">
      <!-- //薪酬设置 -->
      <el-tab-pane label="薪酬设置">
        <el-row>
          <el-col :span="24">
            <div class="grid-content bg-purple-dark title">
              <!-- <img src="~/Verification/tips.png" alt=""> -->
              <img src="../../assets/Verification/tips.png" />
              请仔细核对数据后在执行保存更新。保存后的数据即刻生效。
            </div>
          </el-col>
        </el-row>
        <el-row style="margin-left:200px">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form>
                <el-form-item label="考勤周期:">
                  <el-select v-model="form.region" placeholder="请选择">
                    <el-option label="周期一" value="shanghai"></el-option>
                    <el-option label="周期二" value="beijing"></el-option>
                  </el-select>
                </el-form-item>
              </el-form>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light">
              <el-form>
                <el-form-item label="社保数据源:">
                  <el-select
                    v-model="form.dictName"
                    placeholder="表格导入"
                    @focus="getSocialSecurityKey()"
                    @change="getSocialDatasource ()"
                  >
                    <el-option
                      :label="item.dictName"
                      :value="item.dictName"
                      v-for="item in form.socialSecurity"
                    >{{ item.dictName }}</el-option>
                  </el-select>
                </el-form-item>
              </el-form>
            </div>
          </el-col>
        </el-row>
        <el-row style="margin-left:173px">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form>
                <el-form-item label="社保扣除月份:">
                  <el-select
                    v-model="form.monthSb"
                    placeholder="上月"
                    @focus="getSocialSecurityMonthKey()"
                    @change="getSocialMonth()"
                  >
                    <el-option
                      :label="item.dictName"
                      :value="item.dictName"
                      v-for="item in form.SocialSecurityMonth"
                    >{{ item.dictName }}</el-option>
                  </el-select>
                </el-form-item>
              </el-form>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light">
              <el-form>
                <el-form-item label="公积金数据源:">
                  <el-select
                    v-model="form.provident"
                    placeholder="请选择活动区域"
                    @focus="getProvidentFundKey()"
                    @change="getAccfundDatasource()"
                  >
                    <el-option
                      :label="item.dictName"
                      :value="item.dictName"
                      v-for="item in form.providentFund"
                    >{{ item.dictName }}</el-option>
                  </el-select>
                </el-form-item>
              </el-form>
            </div>
          </el-col>
        </el-row>
        <el-row style="margin-left:159px">
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form>
                <el-form-item label="公积金扣除月份:">
                  <el-select
                    v-model="form.ProvidentMonth"
                    placeholder="上月"
                    @focus="getProvidentFundMonthKey()"
                    @change="getAccfundMonth()"
                  >
                    <el-option
                      :label="item.dictName"
                      :value="item.dictName"
                      v-for="item in form.ProvidentFundMonth"
                    >{{ item.dictName }}</el-option>
                  </el-select>
                </el-form-item>
              </el-form>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light"></div>
          </el-col>
        </el-row>
        <!-- //按钮 -->
        <!-- <el-row>
          <el-col :span="24">
            <div class="grid-content bg-purple-dark" style="width:200px;margin:auto">
              <el-button type="primary" >确定保存</el-button>
              <el-button>取消</el-button>
            </div>
          </el-col>
        </el-row>-->
      </el-tab-pane>
      <!-- 薪酬项设置 -->
      <el-tab-pane label="薪酬项设置">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <div>
              应发工资 =
              {{formAddSubitem.payableFormula}}
              <el-input
                class="input-new-tag"
                v-if="inputVisible"
                v-model="inputValue"
                ref="saveTagInput"
                size="small"
                @keyup.enter.native="handleInputConfirm"
                @blur="handleInputConfirm"
              ></el-input>
              <el-button
                icon="el-icon-circle-plus-outline"
                style="float: right; padding:10px 5px;margin-top:-7px"
                type="primary"
                size="medium"
                @click="dialogVisible1 = true"
              >添加子项</el-button>
            </div>
          </div>
          <!-- tab表格项 税前-->
          <el-table :data="salaryItemArray" border stripe style="width: 70%" center>
            <el-table-column prop="name" label="项目名" style="width:45%"></el-table-column>
            <el-table-column prop="property" label="属性" style="width:45%">
              <template slot-scope="scope">
                <!-- {{scope.row}}{{scope.row.property}} -->
                <span v-if="scope.row.property==1">税前加项</span>
                <span v-else>税前减项</span>
              </template>
            </el-table-column>
            <el-table-column prop="formula" label="公式" style="width:45%"></el-table-column>
            <el-table-column prop label="操作" value="salaryItemArray.operType">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  icon="el-icon-edit"
                  size="mini"
                  @click="getCellKey(scope.$index,scope.row,scope.row.code)"
                >编辑</el-button>
                <el-button
                  type="danger"
                  icon="el-icon-delete"
                  size="mini"
                  @click="deleteCell(scope.row.name)"
                >移除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
        <el-card class="box-card1">
          <div slot="header" class="clearfix">
            <span>
              实发工资 =
              {{formAddSubitem.actualFormula}}
            </span>
            <el-button
              icon="el-icon-circle-plus-outline"
              style="float: right; padding:10px 5px;margin-top:-7px"
              type="primary"
              @click="dialogVisible2 = true"
            >添加子项</el-button>
          </div>
          <!-- //test 税后加减项-->
          <el-table :data="salaryItemArray_b" border stripe style="width: 70%" center>
            <el-table-column prop="name" label="项目名" style="width:45%"></el-table-column>
            <el-table-column prop="property" label="属性" style="width:45%">
              <template slot-scope="scope">
                <!-- {{scope.row}}{{scope.row.property}} -->
                <span v-if="scope.row.property==1">税后加项</span>
                <span v-else>税后减项</span>
              </template>
            </el-table-column>
            <el-table-column prop="formula" label="公式" style="width:45%"></el-table-column>
            <el-table-column prop label="操作" value="salaryItemArray.operType">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  icon="el-icon-edit"
                  size="mini"
                  @click="getCellKey_sh(scope.$index,scope.row,scope.row.code)"
                >编辑</el-button>
                <el-button
                  type="danger"
                  icon="el-icon-delete"
                  size="mini"
                  @click="deleteCell_sh(scope.row.name)"
                >移除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- test -->
          <!-- //按钮 -->
          <!-- <el-row>
            <el-col :span="24">
              <div
                class="grid-content bg-purple-dark"
                style="width:200px;margin:auto;margin-top:20px"
              >
                <el-button type="primary" @click="preserveCellSet">确定保存</el-button>
                <el-button>取消</el-button>
              </div>
            </el-col>
          </el-row> -->
        </el-card>
      </el-tab-pane>
    </el-tabs>

    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark" style="width:200px;margin:auto;margin-top:20px">
          <el-button type="primary" @click="preserveCellSet">确定保存</el-button>
          <el-button>取消</el-button>
        </div>
      </el-col>
    </el-row>
    <!-- 添加子项的dialog1(1.税前的) -->
    <div class="digbox1">
      <el-dialog title="添加税前薪酬项" :visible.sync="dialogVisible1" width="40%">
        <el-divider></el-divider>
        <!-- 表单 -->
        <el-form ref="formAddSubitem" :model="form" label-width="80px">
          <el-form-item label="项名称">
            <el-select
              v-model="formAddSubitem.name"
              filterable
              allow-create
              default-first-option
              placeholder="请输入项名称"
              @change="getSelectValue"
            >
              <el-option :label="item.name" :value="item.name" v-for="item in arr">
                <span style="float: left">{{item.name }}</span>
                <span
                  style="float: right; color: #F56C6C; font-size: 13px"
                  @click="delOption(`${item.name}`)"
                >
                  <span v-if="item.deleteType==1">
                    <i class="el-icon-remove"></i>
                  </span>
                </span>
              </el-option>
            </el-select>
            <span style="margin-left:20px">
              <span v-if="this.switchValue">税前加项</span>
              <span v-else>税前减项</span>
              <el-switch
                v-model="switchValue"
                @change="switchChange()"
                active-color="#13ce66"
                inactive-color="#ff4949"
              ></el-switch>
            </span>
          </el-form-item>
          <div class="aditf">编辑公式：</div>
          <el-form-item>
            <el-row>
              <el-col :span="18">
                <div class="grid-content bg-purple">
                  <el-input
                    @change="getTextarea"
                    type="textarea"
                    v-model="formAddSubitem.desc"
                    style="width:80%;height:80px;dispaly:inline-black"
                    placeholder="直接输入公式,如:销量 *0.06 "
                  ></el-input>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple-light grid-box">
                  <div>操作</div>
                  <div class="btns">
                    <el-button type="text" icon="el-icon-error" style="color:red">删除</el-button>
                    <el-button type="text" icon="el-icon-delete" style="color:#FF9000">清空</el-button>
                  </div>
                </div>
              </el-col>
            </el-row>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible1 = false">取 消</el-button>
          <el-button type="primary" @click="addRuleSeting">确 定</el-button>
        </span>
      </el-dialog>
    </div>
    <!-- 添加子项的dialog2 (2.税后的)-->
    <div class="digbox1">
      <el-dialog title="添加税后薪酬项" :visible.sync="dialogVisible2" width="40%">
        <el-divider></el-divider>
        <!-- 表单 -->
        <el-form ref="formAddSubitem_b" :model="form" label-width="80px">
          <el-form-item label="项名称">
            <el-select
              v-model="formAddSubitem_b.name"
              filterable
              allow-create
              default-first-option
              placeholder="请输入项名称"
              @change="getSelectValue"
            >
              <!-- <el-option :label="item" :value="item" v-for="item in dynamicTags"></el-option> -->
              <el-option :label="item" :value="item" v-for="item in arrFormAddSubitem_b"></el-option>
            </el-select>
            <span style="margin-left:20px">
              <span v-if="this.switchValue_b==true">税后加项</span>
              <span v-else>税后减项</span>
              <el-switch
                v-model="switchValue_b"
                @change="switchChange_b()"
                active-color="#13ce66"
                inactive-color="#ff4949"
              ></el-switch>
            </span>
          </el-form-item>
          <div class="aditf">编辑公式：</div>
          <el-form-item>
            <el-row>
              <el-col :span="18">
                <div class="grid-content bg-purple">
                  <el-input
                    @change="getTextarea_b"
                    type="textarea"
                    v-model="formAddSubitem_b.desc"
                    style="width:80%;height:80px;dispaly:inline-black"
                    placeholder="直接输入公式,如:销量 *0.06 "
                  ></el-input>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple-light grid-box">
                  <div>操作</div>
                  <div class="btns">
                    <el-button type="text" icon="el-icon-error" style="color:red">删除</el-button>
                    <el-button type="text" icon="el-icon-delete" style="color:#FF9000">清空</el-button>
                  </div>
                </div>
              </el-col>
            </el-row>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible2 = false">取 消</el-button>
          <el-button type="primary" @click="addRuleSeting_b">确 定</el-button>
        </span>
      </el-dialog>
    </div>
    <!-- 编辑薪酬项的dialog3(1.税前的) -->
    <el-dialog title="编辑薪酬项" :visible.sync="dialogVisible3" width="30%">
      <el-form ref="Cellform" label-width="100px">
        <el-form-item label="薪酬项名称">
          <el-input v-model="Cellform.name" disabled size="70%"></el-input>
        </el-form-item>
        <el-form-item label="薪酬项公式">
          <el-input v-model="Cellform.formula" size="70%"></el-input>
        </el-form-item>
        <el-form-item>
          <span v-if="switchValue_editsq" style="margin-left:-80px;display:inline-black">税前加项</span>
          <span v-else style="margin-left:-80px;display:inline-black;">税前减项</span>
          <el-switch
            v-model="switchValue_editsq"
            @change="switchChange_editsq()"
            active-color="#13ce66"
            inactive-color="#ff4949"
          ></el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible3 = false">取 消</el-button>
        <el-button type="primary" @click="editCellKey">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 编辑薪酬项的dialog3(1.税后的) -->
    <el-dialog title="编辑薪酬项" :visible.sync="dialogVisible3_sh" width="30%">
      <el-form ref="Cellform_sq" label-width="100px">
        <el-form-item label="薪酬项名称">
          <el-input v-model="Cellform_sh.name" disabled size="70%"></el-input>
        </el-form-item>
        <el-form-item label="薪酬项公式">
          <el-input v-model="Cellform_sh.formula" size="70%"></el-input>
        </el-form-item>
        <el-form-item>
          <span v-if="switchValue_editsh" style="margin-left:-80px;display:inline-black">税前加项</span>
          <span v-else style="margin-left:-80px;display:inline-black;">税前减项</span>
          <el-switch
            v-model="switchValue_editsh"
            @change="switchChange_editsh()"
            active-color="#13ce66"
            inactive-color="#ff4949"
          ></el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible3_sh = false">取 消</el-button>
        <el-button type="primary" @click="editCellKey_sh">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      switchValue_editsh: true, //税后更改项
      switchValue_editsq: true, //税前更改项
      findCodeList: [], //调用根据薪酬code删除薪酬项.带有code的薪酬项
      form: {
        socialSecurity: [], //社保来源的数组
        SocialSecurityMonth: [], //社保月份的数组
        providentFund: [], //公积金来源的数组
        ProvidentFundMonth: [], //公积金月份的数组
        ProvidentMonth: '',
        dictName: '',
        monthSb: '',
        provident: ''
      },
      preserveCellSetFrom: {
        accfundDatasource: '',
        accfundMonth: '',
        socialDatasource: '',
        socialMonth: '',
        payableFormula: '',
        actualFormula: ''
      },
      dialogVisible1: false,
      dialogVisible2: false,
      dialogVisible3: false,
      dialogVisible3_sh: false,
      // formAddSubitem: {
      //   name: ''
      // },
      switchValue: true, //税前的switch开关
      switchValue_b: true, //税后的switch开关
      //税前的
      formAddSubitem: {
        name: '',
        nameAyy: [],
        actualFormula: '',
        payableFormula: ''
      },
      //税后的
      formAddSubitem_b: {
        name: '',
        nameAyy: [],
        actualFormula: '',
        payableFormula: ''
      },
      inputVisible: false,
      inputValue: '',
      dynamicTags: [],
      //添加的数组(税前)
      addRuleList: {
        formula: '',
        name: '',
        property: 0
      },
      //添加的数组(税后)
      addRuleList_b: {
        formula: '',
        name: '',
        property: 0
      },
      arrFormAddSubitem: [],
      arrFormAddSubitem_b: [],
      checkResult: false,
      checkResult_b: false,
      salaryItemArray: [],
      salaryItemArray1: [],
      salaryItemArray_b: [],
      Cellform: {
        code: '',
        name: '',
        formula: '',
        operType: 1
      }, //编辑薪酬项的对象(税前)
      Cellform_sh: {
        code: '',
        name: '',
        formula: '',
        operType: 1
      }, //编辑薪酬项的对象(税后)
      // 税前的薪酬项数据列表
      PretaxList: [], // 税前的薪酬项tab数据列表
      PretaxList_b: [], // 税后的薪酬项tab数据列表
      salaryItemArrayList: [], //模糊查询的数据列表
      arr: [],
      arr_2: []
    }
  },
  methods: {
    //获取当前用户的薪酬规则
    async getUserSalary() {
      const { data: res } = await this.$http.get('salary/ruleSetting')
      // console.log(res.data.salaryRule)
      console.log(res)
      console.log(res.payedItems)
      this.formAddSubitem.actualFormula = res.actualFormula
      this.formAddSubitem.payableFormula = res.payableFormula
      this.formAddSubitem.nameAyy = res.payedItems
      console.log(this.formAddSubitem)
    },
    //获取字典的数据源(社保)
    async getSocialSecurityKey() {
      const { data: res } = await this.$http.get('sys/list/dicts/80003')
      this.form.socialSecurity = res.data.dictionaries
    },
    //通过(社保的)数据来源获取code
    getSocialDatasource() {
      this.form.socialSecurity.forEach(item => {
        if (item.dictName == this.form.dictName) {
          this.preserveCellSetFrom.socialDatasource = item.dictCode
        }
      })
      console.log(this.preserveCellSetFrom.socialDatasource)
    },
    //获取字典的月份(社保)
    async getSocialSecurityMonthKey() {
      const { data: res } = await this.$http.get('sys/list/dicts/80002')
      this.form.SocialSecurityMonth = res.data.dictionaries
      console.log(this.form.SocialSecurityMonth)
    },
    //通过(社保的)的月份来获取对应的code
    getSocialMonth() {
      this.form.SocialSecurityMonth.forEach(item => {
        if (item.dictName == this.form.monthSb) {
          this.preserveCellSetFrom.socialMonth = item.dictCode
        }
      })
      console.log(this.preserveCellSetFrom.socialMonth)
    },
    //获取字典的月份(公积金)
    async getProvidentFundMonthKey() {
      const { data: res } = await this.$http.get('sys/list/dicts/80004')
      this.form.ProvidentFundMonth = res.data.dictionaries
      console.log(this.form.ProvidentFundMonth)
    },
    //通过(公积金)的月份来获取相对应的key
    getAccfundMonth() {
      this.form.ProvidentFundMonth.forEach(item => {
        if (item.dictName == this.form.ProvidentMonth) {
          this.preserveCellSetFrom.accfundMonth = item.dictCode
        }
      })
      console.log(this.preserveCellSetFrom.accfundMonth)
    },
    //获取公积金的数据来源
    async getProvidentFundKey() {
      const { data: res } = await this.$http.get('sys/list/dicts/80005')
      this.form.providentFund = res.data.dictionaries
    },
    //通过(公积金)的数据源来获取相对应的key
    getAccfundDatasource() {
      this.form.providentFund.forEach(item => {
        if (item.dictName == this.form.provident) {
          this.preserveCellSetFrom.accfundDatasource = item.dictCode
        }
      })
      console.log(this.preserveCellSetFrom.accfundDatasource)
    },
    //标签=s
    handleClose(tag) {
      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1)
    },
    showInput() {
      this.inputVisible = true
      this.$nextTick(_ => {
        this.$refs.saveTagInput.$refs.input.focus()
      })
    },
    handleInputConfirm() {
      let inputValue = this.inputValue
      if (inputValue) {
        this.dynamicTags.push(inputValue)
      }
      this.inputVisible = false
      this.inputValue = ''
    },
    //标签=e
    //获取选择框的公式(列表数据啊)
    async getSelectValue() {
      // console.log(this.formAddSubitem)
      this.dynamicTags.forEach(item => {
        if (item == this.formAddSubitem.name) {
          this.dynamicTags.push(this.formAddSubitem.name)
        }
      })
      // console.log(this.dynamicTags)
      const { data } = await this.$http.get(
        `salary/ruleSetting/salaryItems`,
        this.formAddSubitem.name
      )
      // console.log(data, '薪酬项')
      this.salaryItemArrayList = data
      // this.salaryItemArray = data
    },
    //获取文本框输入的值调用相应的接口(税前)
    async getTextarea() {
      // console.log(this.formAddSubitem.desc)
      const { data } = await this.$http.get(
        `salary/ruleSetting/salaryItems`,
        this.formAddSubitem.desc
      )
      console.log(data, '薪酬项')
      this.findCodeList = data
      data.forEach(item => {
        if (item.name) {
          this.arrFormAddSubitem.push(item.name)
        }
      })
      console.log(this.arrFormAddSubitem)
    },
    //获取文本框输入的值调用相应的接口(税后)
    async getTextarea_b() {
      // console.log(this.formAddSubitem.desc)
      const { data } = await this.$http.get(
        `salary/ruleSetting/salaryItems`,
        this.formAddSubitem_b.desc
      )
      console.log(data)
      this.arr = data
      data.forEach(item => {
        if (item.name) {
          this.arrFormAddSubitem_b.push(item.name)
        }
      })
      console.log(this.arrFormAddSubitem_b)
    },
    // switch值改变时事件(税前)
    switchChange() {
      this.switchValue != this.switchValue
      console.log(this.switchValue)
    },
    // switch值改变时事件(税后)
    switchChange_b() {
      this.switchValue_b != this.switchValue_b
      console.log(this.switchValue_b)
    },
    //添加或保存薪酬项(税前)
    async addRuleSeting() {
      // this.addRuleList = {
      //   formula: '',
      //   name: '',
      //   property: 0
      // }
      if (this.switchValue) {
        this.addRuleList.property = 1
      } else {
        this.addRuleList.property = 2
      }
      console.log(this.addRuleList.property)
      this.addRuleList.name = this.formAddSubitem.name
      this.addRuleList.formula = this.formAddSubitem.desc
      this.PretaxList.push(this.$global.deepcopyArray([this.addRuleList])[0])
      this.salaryItemArray = this.PretaxList
      // console.log(this.addRuleList)
      console.log(this.PretaxList)
      this.dialogVisible1 = false
      //检验公式
      let checkResult = this.$global.checkFormula(
        this.formAddSubitem.desc,
        this.arrFormAddSubitem
      )
      console.log('==========checkResult====' + checkResult)
      this.checkResult = checkResult
      // console.log(this.checkResult)
      if (this.checkResult) {
        const { data } = await this.$http.post(
          `salary/ruleSetting/salaryItems`,
          this.addRuleList
        )
        console.log(data)
        if (!data.code == 0) {
          this.$message.error('该薪酬项名称已存在')
        }else{
          this.$message.success('添加薪酬项名称成功')
        }
      }
      this.getSelectValue() //重新获取列表数据
    },
    //添加或保存薪酬项(税后)
    async addRuleSeting_b() {
      if (this.switchValue_b) {
        this.addRuleList_b.property = 1
      } else {
        this.addRuleList_b.property = 2
      }
      console.log(this.addRuleList_b.property)
      this.addRuleList_b.name = this.formAddSubitem_b.name
      this.addRuleList_b.formula = this.formAddSubitem_b.desc

      this.PretaxList_b.push(
        this.$global.deepcopyArray([this.addRuleList_b])[0]
      )

      // this.PretaxList.push(this.addRuleList)
      this.salaryItemArray_b = this.PretaxList_b
      // console.log(this.addRuleList)
      console.log(this.PretaxList_b, 'PretaxList_b')
      this.dialogVisible2 = false
      //检验公式
      let checkResult_b = this.$global.checkFormula(
        this.formAddSubitem.desc,
        this.arrFormAddSubitem
      )
      console.log('==========checkResult====' + checkResult_b)
      this.checkResult_b = checkResult_b
      // console.log(this.checkResult_b)
      if (1) {
        const { data } = await this.$http.post(
          `salary/ruleSetting/salaryItems`,
          this.addRuleList_b
        )
        console.log(data)
        if (!data.code == 0) {
          this.$message.error('该薪酬项名称已存在')
        }else{
          this.$message.success('添加薪酬项名称成功')
        }
      }
      this.getSelectValue() //重新获取列表数据
    },
    //获取当前点击按钮scope.row的值(税前)
    getCellKey(v, q, code) {
      // console.log(code)
      console.log(v, q)
      this.Cellform.code = code
      this.Cellform.name = q.name
      this.Cellform.formula = q.formula
      this.Cellform.property = q.property
      this.dialogVisible3 = true
    },
    //税前编辑更改switch的值
    switchChange_editsq() {
      this.switchChange_editsq != this.switchChange_editsq
    },
    //编辑薪酬项(税前)
    editCellKey() {
      console.log(this.Cellform)
      console.log(this.salaryItemArray)
      // const { data } = await this.$http.put(
      //   `salary/ruleSetting/salaryItems/${this.Cellform.code}`,
      //   this.Cellform
      // )
      if (this.switchChange_editsq) {
        this.Cellform.property = 1
      } else {
        this.Cellform.property = 2
      }
      this.salaryItemArray.forEach(item => {
        if (this.Cellform.name == item.name) {
          if (this.switchChange_editsq) {
            this.Cellform.property = 1
          } else {
            this.Cellform.property = 2
          }
          item.formula = this.Cellform.formula
          item.property = this.Cellform.property
        }
      })

      this.dialogVisible3 = false
      // this.getSelectValue() //重新获取列表数据
    },
    //获取当前点击按钮scope.row的值(税后)
    getCellKey_sh(v, q, code) {
      // console.log(code)
      console.log(v, q)
      this.Cellform_sh.code = code
      this.Cellform_sh.name = q.name
      this.Cellform_sh.formula = q.formula
      this.Cellform_sh.property = q.property
      this.dialogVisible3_sh = true
    },
    //税后编辑更改switch的值
    switchChange_editsh() {
      this.switchChange_editsh != this.switchChange_editsh
    },
    //编辑薪酬项(税后)
    editCellKey_sh() {
      console.log(this.Cellform_sh)
      console.log(this.salaryItemArray_b)
      // const { data } = await this.$http.put(
      //   `salary/ruleSetting/salaryItems/${this.Cellform.code}`,
      //   this.Cellform
      // )
      if (this.switchChange_editsh) {
        this.Cellform_sh.property = 1
      } else {
        this.Cellform_sh.property = 2
      }
      this.salaryItemArray_b.forEach(item => {
        if (this.Cellform_sh.name == item.name) {
          if (this.switchChange_editsh) {
            this.Cellform_sh.property = 1
          } else {
            this.Cellform_sh.property = 2
          }
          item.formula = this.Cellform_sh.formula
          item.property = this.Cellform_sh.property
        }
      })

      this.dialogVisible3_sh = false
      // this.getSelectValue() //重新获取列表数据
    },
    //删除用户列表中的薪酬项(税前)
    deleteCell(value) {
      console.log(value)
      console.log(this)
      let deleteCellCode = ''
      this.findCodeList.forEach(items => {
        if (items.name == value) {
          deleteCellCode = items.code
        }
      })
      // const { data } = await this.$http.delete(
      //   `salary/ruleSetting/salaryItems/${deleteCellCode}`
      // )
      // console.log(data)
      console.log(this.salaryItemArray)
      // this.salaryItemArray.forEach(item => {
      //   if (this.Cellform.name == item.name) {
      //     this.salaryItemArray.remove(item)
      //   }
      // })
      this.getSelectValue() //重新获取列表数据
    },
    //删除薪酬项(税h后)
    deleteCell_sh(value) {
      console.log(value)
      console.log(this.salaryItemArray_b)
      // this.getSelectValue() //重新获取列表数据
    },
    //获取用户添加的薪酬项到设置的(应发工资)和(实发工资)中
    getAddSetRule() {
      // console.log(this.PretaxList)
      //税前的加减薪酬项
      this.PretaxList.forEach(item => {
        if (item.property == 1) {
          this.preserveCellSetFrom.payableFormula += '+' + item.name
        } else {
          this.preserveCellSetFrom.payableFormula += '-' + item.name
        }
      })

      this.preserveCellSetFrom.payableFormula =
        this.formAddSubitem.payableFormula +
        '+' +
        this.preserveCellSetFrom.payableFormula
      //截取字符串
      let str1 = this.preserveCellSetFrom.payableFormula
      console.log(str1.lastIndexOf('+'))
      let str11 = str1.substring(0, str1.lastIndexOf('+'))
      let str12 = str1.substring(str1.lastIndexOf('+') + 1)
      let str100 = str11 + str12
      console.log(str100)
      this.preserveCellSetFrom.payableFormula = str100
      //税后的加减薪酬项
      this.PretaxList_b.forEach(item => {
        if (item.property == 1) {
          this.preserveCellSetFrom.actualFormula += '+' + item.name
        } else {
          this.preserveCellSetFrom.actualFormula += '-' + item.name
        }
      })
      this.preserveCellSetFrom.actualFormula =
        this.formAddSubitem.actualFormula +
        '+' +
        this.preserveCellSetFrom.actualFormula
      //截取字符串
      let str2 = this.preserveCellSetFrom.actualFormula
      console.log(str2.lastIndexOf('+'))
      let str21 = str2.substring(0, str2.lastIndexOf('+'))
      let str22 = str2.substring(str2.lastIndexOf('+') + 1)
      let str200 = str21 + str22
      console.log(str200)
      this.preserveCellSetFrom.actualFormula = str200
    },
    //保存或更新薪酬项设置
    async preserveCellSet() {
      // this.preserveCellSetFrom.actualFormula = this.formAddSubitem.actualFormula  //实发发工资=应发工资-
      // this.preserveCellSetFrom.payableFormula = this.formAddSubitem.payableFormula //应发工资="基本工资"(1)
      this.getAddSetRule()
      console.log(this.preserveCellSetFrom)
      console.log(
        this.preserveCellSetFrom.payableFormula,
        '======' + this.preserveCellSetFrom.actualFormula
      )
      const { data } = await this.$http.post(
        `salary/ruleSetting`,
        this.preserveCellSetFrom
      )
      if(data.code==0){
        this.$message.success('保存薪酬项设置成功')
      }else{
        this.$message.error('保存薪酬项设置失败')
      }
      console.log(data)
      this.getUseTotalRoleMessage()
    },
    //删除option中的某一项(调用根据薪酬code删除薪酬项)
    async delOption(item) {
      // console.log('ok')
      console.log(item)
      var delOptionCode = ''
      this.findCodeList.forEach(items => {
        if (items.name == item) {
          delOptionCode = items.code
        }
      })
      console.log(delOptionCode)
      const { data } = await this.$http.delete(
        `salary/ruleSetting/salaryItems/${delOptionCode}`
      )
      console.log(data)
      this.getTextarea()
    },
    //获取当前用户的薪酬项信息
    async getUseTotalRoleMessage(){
      const {data}= await this.$http.get(`salary/ruleSetting`)
      console.log(data)
    }
  },
  created() {
    this.getUserSalary()
    this.getTextarea() //获取文本框的公式(税前)
    this.getTextarea_b() //获取文本框的公式(税后)
    this.getSelectValue()
  }
}
</script>
<style lang="less">
.digbox1 {
  .el-dialog__title {
    line-height: 8px;
    font-size: 15px;
    color: #303133;
  }
  .el-dialog__body {
    padding: 0;
    margin-top: -20px;
    color: #606266;
    font-size: 14px;
    // word-break: break-all;
  }
  .el-dialog__footer {
    text-align: center;
  }
}
.clearfix {
  .el-tag--dark {
    margin-left: 20px;
  }
}
</style>
<style lang="less" scoped>
.title {
  background-color: #eff3f8;
  height: 34px;
  line-height: 34px;
  img {
    vertical-align: middle;
  }
}
// .box-card1 {
//   margin-top: 30px;
// }
.btns {
  margin-left: -30px;
  margin-top: -10px;
}
.grid-box {
  margin-top: -10px;
  margin-left: -10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
.aditf {
  margin-left: 20px;
}
</style>
